import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    name: 'login',
    hidden: true,
    meta: {
      title: 'Login - 登录',
      hideInMenu: true
    },
    component: () => import('@/views/login/index')
  },
  {
    path: '/404',
    hidden: true,
    component: () => import('@/views/404'),
    meta: {
      hideInMenu: true
    }
  },

  {
    path: '/',
    component: Layout,
    hidden: true,
    redirect: '/home',
    children: [{
      path: 'home',
      name: 'Home',
      component: () => import('@/views/single-page/home'),
      meta: { title: '首页', icon: 'home', hideInMenu: true, affix: true }
    }]
  },

  {
    path: '/service',
    component: Layout,
    name: 'service',
    redirect: '/service/customer',
    meta: { title: '服务号设置', icon: 'example' },
    children: [
      {
        path: 'customer',
        name: 'customer',
        meta: {
          // icon: 'md-trending-up',
          title: '客户列表'
        },
        component: () => import('@/views/service/customer')
      },
      {
        path: 'garage',
        name: 'garage',
        meta: {
          // icon: 'md-trending-up',
          title: '我的车库'
        },
        component: () => import('@/views/service/garage')
      },
      {
        path: 'video',
        name: 'video',
        meta: {
          // icon: 'md-trending-up',
          title: '宣传视频'
        },
        component: () => import('@/views/service/video')
      },
      {
        path: 'introduce',
        name: 'introduce',
        meta: {
          // icon: 'md-trending-up',
          title: '公司介绍'
        },
        component: () => import('@/views/service/introduce')
      }
    ]
  },
  {
    path: '/vehicle-manage',
    component: Layout,
    name: 'vehicle-manage',
    redirect: '/vehicle-manage/vehicle-info',
    meta: { title: '车辆管理', icon: 'example' },
    children: [
      {
        path: 'vehicle-info',
        name: 'vehicle-info',
        meta: {
          // icon: 'md-trending-up',
          title: '车辆信息'
        },
        component: () => import('@/views/vehicle-manage/vehicle-info')
      },
      {
        path: 'vehicle-type',
        name: 'vehicle-type',
        meta: {
          // icon: 'md-trending-up',
          title: '品牌类型'
        },
        component: () => import('@/views/vehicle-manage/vehicle-type')
      }
    ]
  },
  {
    path: '/customer-manage',
    component: Layout,
    children: [{
      path: 'customer-manage',
      name: 'customer-manage',
      component: () => import('@/views/customer-manage'),
      meta: { title: '客户管理', icon: 'example', hideInMenu: true }
    }]
  },
  {
    path: '/order-manage',
    component: Layout,
    children: [{
      path: 'order-manage',
      name: 'order-manage',
      component: () => import('@/views/order-manage'),
      meta: { title: '订单管理', icon: 'example', hideInMenu: true }
    }]
  },
  {
    path: '/departure-manage',
    component: Layout,
    children: [{
      path: 'departure-manage',
      name: 'departure-manage',
      component: () => import('@/views/departure-manage'),
      meta: { title: '发车管理', icon: 'example', hideInMenu: true }
    }]
  },
  {
    path: '/car-manage',
    component: Layout,
    children: [{
      path: 'car-manage',
      name: 'car-manage',
      component: () => import('@/views/car-manage'),
      meta: { title: '收车管理', icon: 'example', hideInMenu: true }
    }]
  },
  {
    path: '/car-breakdown',
    component: Layout,
    children: [{
      path: 'car-breakdown',
      name: 'car-breakdown',
      component: () => import('@/views/car-breakdown'),
      meta: { title: '收车故障', icon: 'example', hideInMenu: true }
    }]
  },
  {
    path: '/deposit-refund',
    component: Layout,
    children: [{
      path: 'deposit-refund',
      name: 'deposit-refund',
      component: () => import('@/views/deposit-refund'),
      meta: { title: '待退押金', icon: 'example', hideInMenu: true }
    }]
  },
  {
    path: '/system',
    name: 'system',
    redirect: '/system/account-manage',
    meta: {
      // icon: 'logo-buffer',
      icon: 'example',
      title: '系统设置'
    },
    component: Layout,
    children: [
      {
        path: 'role-manage',
        name: 'role-manage',
        meta: {
          // icon: 'md-trending-up',
          title: '角色管理'
        },
        component: () => import('@/views/system/role-manage')
      },
      {
        path: 'account-manage',
        name: 'account-manage',
        meta: {
          // icon: 'md-trending-up',
          title: '账户管理'
        },
        component: () => import('@/views/system/account-manage')
      },
      {
        path: 'parameter-config',
        name: 'parameter-config',
        meta: {
          // icon: 'md-trending-up',
          title: '参数设置'
        },
        component: () => import('@/views/system/parameter-config')
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', meta: { hideInMenu: true }}
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
